home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Turnbull China Bikeride
/
Turnbull China Bikeride - Disc 1.iso
/
ARGONET
/
PD
/
MATHS
/
RLAB
/
RLAB125.ZIP
/
!RLaB
/
rlib
/
triu
< prev
next >
Wrap
Text File
|
1994-09-23
|
815b
|
42 lines
//-------------------------------------------------------------------//
// Syntax: triu ( A )
// triu ( A , K )
// Description:
// triu(x) returns the upper triangular part of A.
// tril(x; k) returns the elements on and above the k-th diagonal of
// A.
// K = 0: main diagonal
// K > 0: above the main diag.
// K < 0: below the main diag.
// See Also: tril
//-------------------------------------------------------------------//
triu = function(x, k)
{
if (!exist (k)) { k = 0; }
nr = x.nr; nc = x.nc;
if(k > 0)
{
if (k > (nc - 1)) { error ("triu: invalid value for k"); }
else
if (abs (k) > (nr - 1)) { error ("triu: invalid value for k"); }
}
y = zeros(nr, nc);
for(j in max( [1,1+k] ):nc)
{
i = 1:min( [nr, j-k] );
y[i;j] = x[i;j];
}
return y;
};